package com.tianxia120.website.admin.service;

import cn.hutool.crypto.SecureUtil;
import com.jfinal.plugin.activerecord.Db;
import com.tianxia120.website.bean.model.User;
import com.tianxia120.website.data.entity.Result;
import com.tianxia120.website.data.utils.ResultUtils;

import java.util.List;

/**
 * @createTime: 2018/9/21 13:06
 * @author: HingLo
 * @description: 登录相关的操作
 */
public class LoginService {

    /**
     * 登录相关的服务层
     *
     * @param username 用户名
     * @param password 密码
     * @return 返回登录结果
     */
    public Result login(String username, String password) {
        String sql = Db.getSql("website.login");
        List<User> list = User.dao.find(sql, username, SecureUtil.md5(password));
        if (list.isEmpty() || list.size() > 1) {
            return ResultUtils.error("账号或者密码错误");
        }
        return ResultUtils.success(list.get(0));
    }

}
